package de.fhkl.android.activities;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import de.fhkl.android.R;
import de.fhkl.android.beans.EinrichtungBean;
import de.fhkl.android.beans.PersonBean;
import de.fhkl.android.utils.AndroidUtil;
import de.fhkl.android.utils.ConnectionManager;

public class SearchActivity extends Activity {
	private static final int SEARCH_PERSON = 0;
	private static final int SEARCH_ROOM = 1;
	private static final int SEARCH_TYPE_COUNT = 2;
	private int searchType = SEARCH_PERSON;

	private static String tag = "PersonActivity";

	private ArrayList<Object> searchItemList;
	private static SearchResultListAdapter myListAdapter;
	// url to check people summary
	private static String url_1 = "http://fhinfo-portal-test.fh-kl.de/portalapps/pv/xml/PersonSuche.do";

	// url to check people detail
	private static String url_2 = "http://fhinfo-portal-test.fh-kl.de/portalapps/pv/xml/PersonAction.do";

	// url to check people&room detail
	private static String url_3 = "http://fhinfo-portal-test.fh-kl.de/portalapps/pv/xml/Suche.do";

	private GestureLibrary gestureLib;
	private GestureOverlayView gestureView;
	private LinearLayout window;

	/**
	 * Visit PersonSuche.do (url_1), get the summary of person as xml
	 * 
	 * @param name
	 *            name of the person
	 * @return
	 */
	private static String doPersonSuche(String name) {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
		nameValuePairs.add(new BasicNameValuePair("suchbegriff", name));
		return ConnectionManager.post(url_1, nameValuePairs);

	}

	private static ListView searchResultListView;

	/**
	 * Visit PersonAction.do(url_2),get the detail of person as xml
	 * 
	 * @param pid
	 *            id of the person
	 * @return
	 */
	private static String doPersonAction(String pid) {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
		nameValuePairs.add(new BasicNameValuePair("method", "externView"));
		nameValuePairs.add(new BasicNameValuePair("pid", pid));
		return ConnectionManager.post(url_2, nameValuePairs);
	}

	/**
	 * Visit Suche.do,get both raum and person information as xml
	 * 
	 * @param searchType
	 * @param suchbegriff
	 * @return
	 */
	private static String doSuche(int searchType, String suchbegriff) {

		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

		switch (searchType) {
		case SEARCH_PERSON:
			nameValuePairs.add(new BasicNameValuePair("suchbereich", "person"));
		case SEARCH_ROOM:
			nameValuePairs.add(new BasicNameValuePair("suchbereich", "raum"));
		}
		nameValuePairs.add(new BasicNameValuePair("suchbegriff", suchbegriff));
		return ConnectionManager.post(url_3, nameValuePairs);
	}

	public void onCreate(Bundle savedInstanceState) {
		Log.i(tag, "begin");
		super.onCreate(savedInstanceState);
		searchType = SEARCH_PERSON;

		

		initView();
		Log.i(tag, "end");
	}

	private void initView() {
		int displayWidth = AndroidUtil.getDisplayWidth(this);

		/**
		 * Main View of PeopleActivity.
		 */
		gestureLib = GestureLibraries
				.fromRawResource(this, R.raw.gestures_main);
		if (!gestureLib.load()) {
			Toast.makeText(this, "Could not load R.raw.gestures_main",
					Toast.LENGTH_SHORT).show();
			finish();
		}
		gestureView = new GestureOverlayView(this);
		gestureView.setFadeOffset(100);
		gestureView.setGestureVisible(true);
		gestureView.setLayoutParams(new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.FILL_PARENT,
				ViewGroup.LayoutParams.FILL_PARENT));
		gestureView
				.addOnGesturePerformedListener(new OnGesturePerformedListener() {
					public void onGesturePerformed(GestureOverlayView view,
							Gesture gesture) {

						ArrayList<Prediction> predictions = gestureLib
								.recognize(gesture);
						Log.i("gestureView",
								"onGesturePerformed" + predictions.size());
						if (predictions.size() > 0) {
							Prediction prediction = (Prediction) predictions
									.get(0);
							Log.w("score", prediction.score + "");
							if (prediction.score > 50) {
								if (prediction.name.equals("left")) {
									searchType = ((searchType - 1) + SEARCH_TYPE_COUNT)
											% SEARCH_TYPE_COUNT;
									Log.w("window", "go left,searchType="
											+ searchType);
									initView();
								} else if (prediction.name.equals("right")) {
									searchType = (searchType + 1)
											% SEARCH_TYPE_COUNT;
									Log.w("window", "go right,searchType="
											+ searchType);
									initView();
								}

							}
						}
					}
				});

		window = new LinearLayout(this);
		window.setOrientation(LinearLayout.VERTICAL);
		window.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT));
		window.setBackgroundColor(Color.WHITE);

		window.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Log.i("window onClick", "onClick");
			}

		});
		window.setOnTouchListener(new changeSearchTypeListener());
		final LinearLayout resultView = new LinearLayout(this);
		resultView.setOrientation(LinearLayout.VERTICAL);
		resultView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT));
		/**
		 * Create a View for search people. include a EditText and a
		 * search-button.
		 * */
		LinearLayout searchbarView = new LinearLayout(this);
		final EditText searchInput = new EditText(this);
		ImageButton searchButton = new ImageButton(this);

		searchButton.setBackgroundResource(android.R.drawable.ic_menu_search);
		Log.i("", "searchType=" + searchType);
		switch (searchType) {
		case SEARCH_PERSON:
			searchInput.setHint(R.string.input_name);
			break;
		case SEARCH_ROOM:
			searchInput.setHint(R.string.input_room);
			break;
		default:
			searchInput.setHint(R.string.input_name);
		}
		searchInput.setSingleLine(true);
		searchInput.setLayoutParams(new LayoutParams(displayWidth - 70, 70));
		searchInput.requestFocus();

		searchbarView.setGravity(Gravity.RIGHT);
		searchbarView.setLayoutParams(new LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

		searchbarView.addView(searchInput);
		searchbarView.addView(searchButton);

		searchButton.setOnClickListener(new OnClickListener() {
			public void onClick(View view) {
				Context context = view.getContext();
				String suchbegriff = searchInput.getText().toString();
				searchInput.setText(new String());
				String xml;
				switch (searchType) {
				case SEARCH_PERSON:
					Log.w("case SEARCH_PERSON", "case SEARCH_PERSON");
					xml = doPersonSuche(suchbegriff);
					searchItemList = parsePersonSummaryXml(xml);
					break;
				case SEARCH_ROOM:
					Log.w("case SEARCH_ROOM", "case SEARCH_ROOM");
					xml = doSuche(searchType, suchbegriff);
					searchItemList = parseRoomXml(xml);
					break;
				}
				Log.e("searchItemList",
						"searchItemList.size=" + searchItemList.size());
				searchResultListView = new ListView(context);
				searchResultListView
						.setOnTouchListener(new changeSearchTypeListener());
				Log.e("do", "do-0");
				searchResultListView.setLayoutParams(new LayoutParams(
						LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
				Log.e("do", "do-1");
				myListAdapter = new SearchResultListAdapter(context,
						searchItemList);
				Log.e("do", "do-2");
				searchResultListView.setAdapter(myListAdapter);
				Log.e("do", "do-3");
				resultView.removeAllViews();
				Log.e("do", "do-4");
				Log.i("resultView", "removeAllViews");
				Log.e("do", "do-5");
				resultView.addView(searchResultListView);
				Log.i("resultView", "addView(searchResultListView)");

			}
		});
		window.addView(searchbarView);
		Log.i("resultView", "window.addView(searchbarView);");
		window.addView(resultView);
		Log.i("resultView", "window.addView(resultView);");

		// setContentView(window);
		gestureView.addView(window);
		setContentView(gestureView);
	}

	@SuppressWarnings("unchecked")
	private ArrayList<Object> parsePersonSummaryXml(String xml) {
		SAXReader saxReader = new SAXReader();
		saxReader.setEncoding("UTF-8");
		saxReader.setValidation(false);
		saxReader.setStringInternEnabled(false);
		saxReader.setMergeAdjacentText(false);
		Document doc = null;
		Log.i("parseSummaryXml", "Xml=" + xml);
		Log.i("parseSummaryXml", "parsePersonSummaryXml-1");
		try {
			doc = saxReader.read(new StringReader(xml));
		} catch (DocumentException e1) {
			Log.e("error", e1.toString());
		}
		Log.i("parseSummaryXml", "parsePersonSummaryXml-2");
		Element resultsElem = doc.getRootElement();
		List<Element> resultList = resultsElem.elements("result");
		Log.i("resultList", "resultList.size=" + resultList.size());
		ArrayList<Object> itemList = new ArrayList<Object>(resultList.size());

		for (int i = 0; i < resultList.size(); i++) {
			Log.i("parseSummaryXml", "parseSummaryXml-loop" + i);
			PersonBean person = new PersonBean();
			Element resultElem = resultList.get(i);

			/**
			 * Big Problem! id become count??!!
			 */
			person.setId(resultElem.attributeValue("count"));
			person.setName(resultElem.elementText("name"));
			person.setRoom(resultElem.elementText("room"));
			person.setTelephone(resultElem.elementText("telephone"));
			person.setEmail(resultElem.elementText("email"));
			itemList.add(person);
		}
		Log.i("parseSummaryXml", "parsePersonSummaryXml-4");
		return itemList;
	}

	private static PersonBean parsePersonDetailXml(String xml) {
		SAXReader saxReader = new SAXReader();
		PersonBean person = new PersonBean();
		saxReader.setEncoding("UTF-8");
		try {
			// Document document = saxReader.read(url);
			Document document = saxReader.read(new StringReader(xml));
			Log.i("parseDetailXml", "parseDetailXml-begin");

			person.setTitle(document.selectSingleNode("/results/result/titles")
					.getText());

			person.setFirstname(document.selectSingleNode(
					"/results/result/firstname").getText());
			person.setLastname(document.selectSingleNode(
					"/results/result/lastname").getText());
			person.setName(person.getTitle() + " " + person.getFirstname()
					+ " " + person.getLastname());

			person.setFachbereich(document.selectSingleNode(
					"/results/result/fachbereich").getText());

			person.setRoom(document.selectSingleNode("/results/result/room")
					.getText());

			person.setStandort(document.selectSingleNode(
					"/results/result/standort").getText());

			person.setTelephone(document.selectSingleNode(
					"/results/result/telephone").getText());

			person.setEmail(document.selectSingleNode("/results/result/email")
					.getText());

			person.setHomepage(document.selectSingleNode(
					"/results/result/homepage").getText());

			person.setSprechstunde(document.selectSingleNode(
					"/results/result/sprechstunde").getText());

			person.setImgurl(document
					.selectSingleNode("/results/result/imgurl").getText());

			Log.i("parseDetailXml", "parseDetailXml-finish");

		} catch (DocumentException e) {
			Log.i("Bean11", e.getMessage());
		}
		return person;
	}

	private ArrayList<Object> parseRoomXml(String xml) {
		SAXReader saxReader = new SAXReader();
		saxReader.setEncoding("UTF-8");
		saxReader.setValidation(false);
		saxReader.setStringInternEnabled(false);
		saxReader.setMergeAdjacentText(false);
		Log.e(tag, xml);
		Document doc = null;
		try {
			doc = saxReader.read(new StringReader(xml));
		} catch (DocumentException e1) {
			Log.e("error", e1.toString());
		}
		Element rootElem = doc.getRootElement();
		Log.e("doc.getRootElement()", rootElem.asXML());
		Element einrichtungen = (Element) (rootElem.elements("einrichtungen")
				.get(0));
		@SuppressWarnings("unchecked")
		List<Element> einrichtungList = einrichtungen.elements("einrichtung");
		ArrayList<Object> itemList = new ArrayList<Object>(
				einrichtungList.size());

		for (int i = 0; i < einrichtungList.size(); i++) {
			Log.i("parseSummaryXml", "parseRoomXml-loop" + i);
			EinrichtungBean einrichtung = new EinrichtungBean();
			Element resultElem = einrichtungList.get(i);
			/**
			 * Big Problem! id become count??!!
			 */
			einrichtung.setId(resultElem.attributeValue("count"));
			einrichtung.setName(resultElem.elementText("name"));
			einrichtung.setRaum(resultElem.elementText("raum"));
			einrichtung.setGebaeude(resultElem.elementText("gebaeude"));
			einrichtung.setStandort(resultElem.elementText("standort"));
			einrichtung.setGruppe(resultElem.elementText("gruppe"));
			einrichtung.setTelefon(resultElem.elementText("telefon"));
			einrichtung.setBereich(resultElem.elementText("bereich"));
			einrichtung.setFax(resultElem.elementText("fax"));
			itemList.add(einrichtung);
		}
		Log.i("parseRoomXml", "parseRoomXml-4");
		return itemList;
	}

	public static WebView createPersonSummaryWebView(final PersonBean person,
			final Context context) {
		Log.d("createPersonSummaryWebView", "createPersonSummaryWebView=0");
		WebView wv = new WebView(context);
		wv.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				return true;
			}
		});
		Document doc = DocumentHelper.createDocument();
		Element body = DocumentHelper.createElement("body");
		doc.setRootElement(body);

		Element div1 = DocumentHelper.createElement("div");
		div1.setText(person.getName());
		body.add(div1);

		Element div2 = DocumentHelper.createElement("div");
		div2.setText(person.getRoom());

		Element div3 = DocumentHelper.createElement("div");
		div3.setText(person.getTelephone());

		Element div4 = DocumentHelper.createElement("div");
		div4.setText(person.getEmail());

		body.add(div2);
		body.add(div3);
		body.add(div4);
		wv.loadData(doc.asXML(), "text/html", "utf-8");

		wv.setOnTouchListener(new OnTouchListener() {

			public boolean onTouch(View wv, MotionEvent event) {
				Log.i("haha", "onTouch");
				if (event.getAction() == MotionEvent.ACTION_UP) {
					String xml = doPersonAction(person.getId());
					PersonBean person = parsePersonDetailXml(xml);
					myListAdapter.replaceView((WebView) wv,
							createPersonDetailWebView(person, wv.getContext()));
					myListAdapter.notifyDataSetChanged();
					Log.e(tag, "myListAdapter.notifyDataSetChanged()");
				}
				return false;
			}

		});

		Log.d("createPersonSummaryWebView", "createPersonSummaryWebView=1");
		return wv;
	}

	/**
	 * Convert Person Object to a Html code for the Person Detail WebView
	 * 
	 * @return Html code as a string.
	 */
	public static WebView createPersonDetailWebView(final PersonBean person,
			final Context context) {
		Log.d("createPersonDetailWebView", "createPersonDetailWebView=1");
		Document doc = DocumentHelper.createDocument();
		Element body = DocumentHelper.createElement("body");
		doc.setRootElement(body);

		Element img = DocumentHelper.createElement("img");
		img.addAttribute("src", person.getImgurl());
		img.addAttribute("width", "35");
		img.addAttribute("style", "position:absolute;right:0");
		body.add(img);

		Element div = DocumentHelper.createElement("div");
		div.setText(person.getTitle() + " " + person.getFirstname() + " "
				+ person.getLastname());
		body.add(div);

		Element table = DocumentHelper.createElement("table");
		table.addAttribute("style", "font-size:5");
		body.add(table);
		Log.d("convertDetailHtml", "convertDetailHtml=2");
		for (int i = 0; i < person.detailList.size(); i++) {
			Log.d("convertDetailHtml", "convertDetailHtml=i=" + i);
			Element tr = DocumentHelper.createElement("tr");
			tr.addAttribute("valign", "top");
			table.add(tr);

			Element td1 = DocumentHelper.createElement("td");
			td1.setText((String) person.detailList.get(i) + ":");
			td1.addAttribute("style", "font-weight:800");
			tr.add(td1);

			Element td2 = DocumentHelper.createElement("td");
			td2.setText((String) person.detailList.getValue(i));
			tr.add(td2);
		}
		Log.d("convertDetailHtml", doc.asXML());

		WebView wv = new WebView(context);
		wv.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				return true;
			}
		});
		wv.getSettings().setBuiltInZoomControls(true);
		wv.loadData(doc.asXML(), "text/html", "utf-8");
		wv.setOnTouchListener(new OnTouchListener() {
			private float x, y;

			public boolean onTouch(View view, MotionEvent event) {
				Log.i("onTouch", event.getEventTime() - event.getDownTime()
						+ "");
				if (event.getAction() == MotionEvent.ACTION_DOWN) {
					x = event.getX();
					y = event.getY();
				}
				if (event.getAction() == MotionEvent.ACTION_UP) {
					double distance = Math.sqrt(Math.pow((event.getX() - x), 2)
							+ Math.pow((event.getY() - y), 2));

					if (event.getEventTime() - event.getDownTime() > 1500
							&& distance < 10) {

						Log.i("longClick", "longClick");
						AlertDialog.Builder builder = new AlertDialog.Builder(
								context);
						builder.setTitle(R.string.choose_searchPerson_action);
						LinearLayout dialogView = new LinearLayout(context);
						dialogView.setLayoutParams(new LayoutParams(
								LayoutParams.WRAP_CONTENT,
								LayoutParams.WRAP_CONTENT));
						dialogView.setOrientation(LinearLayout.VERTICAL);
						Button button1 = new Button(context);
						Button button2 = new Button(context);
						Button button3 = new Button(context);
						Button button4 = new Button(context);
						dialogView.addView(button1);
						dialogView.addView(button2);
						dialogView.addView(button3);
						dialogView.addView(button4);

						button1.setText(R.string.write_a_email);
						button1.setOnClickListener(new OnClickListener() {
							public void onClick(View arg0) {
								String email = person.getEmail();
								email = "zhxi0001@stud.fh-kl.de";
								String subject = "Sehr geehtes "
										+ person.getName() + ",";
								Intent i = new Intent(Intent.ACTION_SEND);
								i.setType("text/plain");
								i.putExtra(Intent.EXTRA_EMAIL,
										new String[] { email });
								i.putExtra(Intent.EXTRA_SUBJECT, subject);
								context.startActivity(i);
							}
						});
						button2.setText(R.string.make_a_phonecall);
						button2.setOnClickListener(new OnClickListener() {
							public void onClick(View arg0) {
								String tel = person.getTelephone();
								tel = "017662188528";
								Intent i = new Intent(Intent.ACTION_DIAL);
								i.putExtra(Intent.EXTRA_PHONE_NUMBER, tel);
								context.startActivity(i);
							}

						});
						button3.setText(R.string.visit_the_homepage);
						button3.setOnClickListener(new OnClickListener() {
							public void onClick(View arg0) {
								String url = person.getHomepage();
								Intent i = new Intent(Intent.ACTION_VIEW);
								i.putExtra(SearchManager.QUERY, url);
								context.startActivity(i);
							}

						});
						button4.setText(R.string.find_the_path);
						button4.setOnClickListener(new OnClickListener() {
							public void onClick(View arg0) {
								Log.i("onClick", "start search path");
							}
						});

						builder.setView(dialogView);

						AlertDialog dialog = builder.create();
						dialog.show();
					}
				}
				return false;
			}
		});
		return wv;
	}

	public static WebView createRoomWebView(final EinrichtungBean room,
			final Context context) {
		WebView wv = new WebView(context);
		wv.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				return true;
			}
		});
		Document doc = DocumentHelper.createDocument();
		Element body = DocumentHelper.createElement("body");
		doc.setRootElement(body);
		Element div0 = DocumentHelper.createElement("div");
		div0.addAttribute("style", "font-weight:800");
		div0.setText(room.getName());

		Element div1 = DocumentHelper.createElement("div");
		div1.setText(room.getBereich());
		div1.addAttribute("style", "font-size:12;color:blue");

		Element div2 = DocumentHelper.createElement("div");
		div2.addAttribute("style", "font-size:12;float:left;color:blue");
		div2.setText(room.getRaum() + ", " + room.getStandort());
		Element div3 = DocumentHelper.createElement("div");
		div3.addAttribute("style", "font-size:12;float:right;color:blue");
		div3.setText(room.getTelefon());
		body.add(div0);
		body.add(div1);
		body.add(div2);
		body.add(div3);
		wv.loadData(doc.asXML(), "text/html", "utf-8");
		wv.setOnTouchListener(new OnTouchListener() {

			public boolean onTouch(View wv, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_UP) {
				}
				return false;
			}

		});

		Log.d("createPersonSummaryWebView", "createPersonSummaryWebView=1");
		return wv;
	}

	class changeSearchTypeListener implements OnTouchListener {
		private float x;

		public boolean onTouch(View v, MotionEvent event) {
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
				x = event.getX();
			}
			if (event.getAction() == MotionEvent.ACTION_UP) {
				float distance = event.getX() - x;
				if (distance > 100) {
					searchType = (searchType + 1) % SEARCH_TYPE_COUNT;
					Log.w("window", "go right,searchType=" + searchType);
					initView();
				} else if (distance < -100) {
					searchType = ((searchType - 1) + SEARCH_TYPE_COUNT)
							% SEARCH_TYPE_COUNT;
					Log.w("window", "go left,searchType=" + searchType);
					initView();
				}
			}
			Log.i("window OnTouch", "getAction" + event.getAction());
			return false;
		}
	}

	class SearchResultListAdapter extends BaseAdapter {
		public ArrayList<WebView> viewList = new ArrayList<WebView>();

		public SearchResultListAdapter(Context context,
				ArrayList<Object> itemList) {
			if (searchType == 0) {
				for (int i = 0; i < itemList.size(); i++) {
					PersonBean person = (PersonBean) itemList.get(i);
					WebView wv = SearchActivity.createPersonSummaryWebView(
							person, context);
					Log.e("SearchResultListAdapter", "searchType == 0");
					viewList.add(wv);
				}
			} else if (searchType == 1) {
				for (int i = 0; i < itemList.size(); i++) {
					EinrichtungBean room = (EinrichtungBean) itemList.get(i);
					WebView wv = SearchActivity
							.createRoomWebView(room, context);
					Log.e("SearchResultListAdapter", "searchType == 1");
					viewList.add(wv);
				}
			}

		}

		public void replaceView(WebView view0, WebView view1) {
			for (int i = 0; i < viewList.size(); i++) {
				if (viewList.get(i) == view0) {
					viewList.add(i, view1);
					viewList.remove(i + 1);
					this.notifyDataSetChanged();
					break;
				}
			}
		}

		public int getCount() {
			return viewList.size();
		}

		public View getItem(int position) {
			return viewList.get(position);
		}

		public long getItemId(int position) {
			return position;
		}

		public WebView getView(int position, View convertView, ViewGroup parent) {
			return viewList.get(position);
		}

		public void replacView() {
		}

	}

}
